package com.bao.work.generics05;

import java.util.Arrays;
import java.util.Comparator;

/**
 * @author baoye
 * @date 2024-07-30/19:17
 */
public class Main {
    public static void main(String[] args) {
        String[] strings = {"afx", "bugc", "ad", "abdu", "bojv"};
        sort(strings);
        System.out.println(Arrays.toString(strings));
    }

    public static <T extends Comparable<T>> void sort(T[] arr) {
        for (int i = 0; i < arr.length; i++) {
            for (int j = 1; j < arr.length - i; j++) {
                if (arr[j].compareTo(arr[j - 1]) < 0) {
                    T temp = arr[j];
                    arr[j] = arr[j - 1];
                    arr[j - 1] = temp;
                }
            }
        }
    }
    public static <T> void sort(T[] arr, Comparator<? super T> c){
        for (int i = 0; i < arr.length; i++) {
            for (int j = 1; j < arr.length - i; j++) {
                if (c.compare(arr[j],arr[j-1])>0) {
                    T temp = arr[j];
                    arr[j] = arr[j - 1];
                    arr[j - 1] = temp;
                }
            }
        }
    }

}

